import { _decorator, Animation, Component, Node } from 'cc';
import { GameManager } from '../GameManager';
const { ccclass, property } = _decorator;

@ccclass('Spark')
export class Spark extends Component {
   
    private anim: Animation | null = null;

    onLoad() {
        // 确保获取到Animation组件
        if (!this.anim) {
            this.anim = this.getComponent(Animation);
            // 监听动画事件
            this.anim.on(Animation.EventType.FINISHED, this.onAnimationFinished, this);
        }
    }

    /**
     * 动画执行完执行
     */
    private onAnimationFinished() {
      GameManager.Instance.delPrefab(this.node, 0)
    }
    
    trySpark(){
        if(this.anim){
            this.anim.play('spark')
        }
    }
}

